package com.lzq.springbook.config;

import com.lzq.springbook.model.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class ErrorAdvice {

    @ExceptionHandler
    public Object handler(Exception e){
        return Result.fail("发生异常: "+e.getMessage());
    }

    @ExceptionHandler
    public Object handler2(NullPointerException e){
        return Result.fail("发生空指针异常: "+e.getMessage());
    }

    @ExceptionHandler
    public Object handler3(IndexOutOfBoundsException e){
        return Result.fail("发生下标越界异常: "+e.getMessage());
    }

    @ExceptionHandler
    public Object handler3(ArithmeticException e){
        return Result.fail("发生算数异常: "+e.getMessage());
    }
}
